Difference between DataTable.Load() and DataTable = dataSet.Tables[];

Posted by subbu on Stack Overflow See other posts from Stack Overflow or by subbu
Published on 2010-03-31T10:00:54Z Indexed on 2010/03/31 10:03 UTC
Read the original article Hit count: 770

Filed under:

Hi All ,

I have a doubt i use the following piece of code get data from a SQLlite data base and Load it into a data table

"SQLiteConnection cnn = new SQLiteConnection("Data Source=" + path);

            cnn.Open();

            SQLiteCommand mycommand = new SQLiteCommand(cnn);
            string sql = "select Company,Phone,Email,Address,City,State,Zip,Country,Fax,Web from RecordsTable";
            mycommand.CommandText = sql;

            SQLiteDataReader reader = mycommand.ExecuteReader();

            dt.Load(reader);

            reader.Close();

            cnn.Close();" 

In some cases when I try to load it Gives me "Failed to enable constraints exception"

But when I tried this below given piece of code for same table and same set of records it worked

"SQLiteConnection ObjConnection = new SQLiteConnection("Data Source=" + path);

           SQLiteCommand ObjCommand = new SQLiteCommand("select Company,Phone,Email,Address,City,State,Zip,Country,Fax,Web from RecordsTable", ObjConnection);
            ObjCommand.CommandType = CommandType.Text;

            SQLiteDataAdapter ObjDataAdapter = new SQLiteDataAdapter(ObjCommand);

            DataSet dataSet = new DataSet();

            ObjDataAdapter.Fill(dataSet, "RecordsTable");

            dt = dataSet.Tables["RecordsTable"];  "

Can any one tell me what is the difference between two

© Stack Overflow or respective owner

Related posts about c#